﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Mes.质检管理.InspectionModel;
using Mes.质检管理.MaterialChenck;
using Mes.质检管理.ProductCheck;


namespace Mes.质检管理
{
    public partial class Chencknavigation : Form
    {
        private Form currentChildForm;

        public Chencknavigation()
        {
            InitializeComponent();
        }

        private void Chencknavigation_Load(object sender, EventArgs e)
        {
            // 默认显示“质检管理”
            OpenChild(new QueckChenck());
        }

        private void menuInspectionAdd_Click(object sender, EventArgs e)
        {
            OpenChild(new InspectionAdd());
        }

        private void menuInspectionShow_Click(object sender, EventArgs e)
        {
            OpenChild(new InspectionShow());
        }

        // 原料质检 - 新增
        private void menuRmAdd_Click(object sender, EventArgs e)
        {
            OpenChild(new MaterialCheckAdd());
        }

        // 原料质检 - 显示
        private void menuRmShow_Click(object sender, EventArgs e)
        {
            OpenChild(new QueckChenck());
        }

        // 原料质检 - 详情
        private void menuRmDetail_Click(object sender, EventArgs e)
        {
            OpenChild(new PlaceholderForm("原料质检详情（待实现）"));
        }

        // 产品质检 - 显示
        private void menuProdShow_Click(object sender, EventArgs e)
        {
            OpenChild(new ProductCheckShow());
        }

        // 产品质检 - 添加
        private void menuProdAdd_Click(object sender, EventArgs e)
        {
            OpenChild(new ProductCheckAdd());
        }

        private void OpenChild(Form child)
        {
            if (currentChildForm != null)
            {
                currentChildForm.Close();
                currentChildForm.Dispose();
            }

            currentChildForm = child;
            child.TopLevel = false;
            child.FormBorderStyle = FormBorderStyle.None;
            child.Dock = DockStyle.Fill;
            this.panelContent.Controls.Clear();
            this.panelContent.Controls.Add(child);
            child.Show();
        }
    }

    internal class PlaceholderForm : Form
    {
        private readonly string placeholderText;

        public PlaceholderForm(string text)
        {
            this.placeholderText = text;
            InitializeUi();
        }

        private void InitializeUi()
        {
            this.BackColor = System.Drawing.Color.White;
            this.Padding = new Padding(20);

            Label label = new Label();
            label.Text = this.placeholderText;
            label.Dock = DockStyle.Fill;
            label.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            label.Font = new System.Drawing.Font("Microsoft YaHei UI", 12F);

            this.Controls.Add(label);
        }
    }
}
